<extend name="Layout:layout_edit" />
<block name="head_after_block">
    <link href="__THEME__Css/frm_queue_status.css" rel="stylesheet" type="text/css"/>
</block>
<block name="body_before_block">
    <script src="__THEME__Plugin/jquery-gridtimer-1.0/jquery-gridtimer-1.0.js" type="text/javascript"></script>
</block>
<block name="body_content_block">
    {$buttons}
    <input type="text" id="grid-timer" value="10" />
    <!--
    <form>
        队列：<input type="text" class="easyui-combobox" id="queue" name="queue" data-url="{:AddonU('Queue/get_queue_json')}" />      
        <a href="#" class="easyui-linkbutton lnk_grid_search" iconCls="icon-search" plain="true">筛选</a>
        分机号：<input type="text" id="extension" name="extension" class="easyui-combobox" data-url="{:AddonU('Extension/get_extension_json')}" />        
        <a href="#" class="easyui-linkbutton lnk_grid_search" iconCls="icon-search" plain="true">筛选</a>
        <a href="#" id="lnk-hash"></a>
    </form>
    -->
    <div id="container" data-url="__SELF__">{$content}</div>
    <input type="hidden" id="idlestateurl" value="{:AddonU('CtiManager/seat_queuePause','opt=varopt&extension=varextension&queue=varqueue&idx=varidx')}" />
</block>
<block name="body_after_block">
    <script type="text/javascript">
        // 页面初始化        
        //$('#queue').combobox({url: $('#queue').data('url'), valueField: 'id', textField: 'text'});
        //$('#extension').combobox({url: $('#extension').data('url'), valueField: 'id', textField: 'text'});
        //$('.lnk_grid_search').click(function () {
        //    var val = $(this).prev().find(':hidden').val();
        //    $('#lnk-hash').attr('href', '#' + val).trigger('click');
        //})
        item_form.resize_owner_dialog({width:880});
        $(document).ready(function () {
            $('#grid-timer').gridTimer({elapsed: function () {
                    $('#container').load($('#container').data('url'), function () {
                        event_binder();
                    });
                }});
        })
        event_binder();
        function event_binder() {
            $('.lnk_info').click(function () {
                curd_grid.lnk_info_event(this);
                return false;
            })
            $('.attr .lnk_switch').click(function () {
                var $this = $(this);
                if ('[-]' == $this.text()) {
                    $this.text('[+]').parent().next().toggle();
                } else {
                    $this.text('[-]').parent().next().toggle();
                }
            })
            $('h3 .lnk_switch').click(function () {
                var $this = $(this);
                if ('[-]' == $this.text()) {
                    $this.text('[+]').parent().parent().next().toggle();
                } else {
                    $this.text('[-]').parent().parent().next().toggle();
                }
            })

            $('td :checkbox').change(function () {
                var url = $('#idlestateurl').val();
                var $this = $(this);
                url = url.replace('varopt', $this.prop('checked') ? 'BUSY' : 'FREE');
                url = url.replace('varextension', $this.data('extension'));
                url = url.replace('varqueue', $this.data('queue'));
                url = url.replace('varidx', $this.parent().parent().parent().attr('id'));
                url = url.replace('.html', '/jsonp/idle_handler.html');
                $.ajax({url: url, dataType: "jsonp", jsonp: 'idle_handler', beforeSend: function () {
                        // ajax_show_loading(false);
                    }});
            })
        }
        // 更改呼叫速度 2014-10-6 by sutroon
        $('#speed').change(function () {
            var val = $(this).val();
            if (!confirm('您确定要更改呼叫速度吗?')) {
                return;
            }
            var url = $(this).data('updateUrl');
            if (undefined == url) {
                alert('URL错误!');
                return;
            }
            $.get(url.replace('varspeed', val), function (data) {
                if (data.status) {
                    $.somessager.alert('提示', data.message);
                } else {
                    alert(data.info);
                }
            })
        })

        function idle_handler(data) {
            if (data.status) {
                $.messager.alert('消息', '操作成功.');
                $('#' + data.info.idx).find('.exten_state_text').html(('示忙' == data.info.state_text ? '<span style="color:#F00">' + data.info.state_text + '</span>' : data.info.state_text));
            } else {
                $.messager.alert('错误', data.message);
            }
        }
    </script>
</block>